import {
    msg,
    close
} from '../../common/utils.js';
import Vue from 'vue';
import {
    serverPath,
    json,
    currentPath
} from '../../common/config.js';
import ArticlesService from '../services/articlesService.js';

window.Module = function () {
    let articlesService = new ArticlesService();
    return new Vue({
        el: '#addPageController',
        data: {
            entity: {

            }
        },
        methods: {
            add: async function () {
                if (!validator.checkAll('form')) {
                    layer.msg('请填写正确参数');
                    return;
                }
                let res = await articlesService.createArticles(this.entity);
                if (!res.type) {
                    for (var item in res) {
                        msg(res[item][0]);
                        break;
                    }
                }
                else{
                    var response = res.body;
                    if('Success' == response.result){
                        this.close();
                    }
                    else{
                        msg(response.message);
                    }
                }
            },
            close: function () {
                close();
            }
        }
    });
}